<?php

namespace app\api\command;

use app\common\model\stock\StockYtdPrice;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Exception;
use app\common\model\stock\Stock;
use app\common\model\GupiaoJihePrice;
use app\common\define\StockDefine;

/**
 * 主板
 * 获取股票集合竞价时间段的数据（工作日每天早上9:20分执行）
 * Class StockCallAuction
 * @package app\api\command
 */
class StockCallAuctionMain extends Command{

    protected function configure(){
        $this->setName('StockCallAuctionMain')->setDescription('获取股票集合竞价的实时价格（主板）');
    }

    protected function execute(Input $input, Output $output){
        $token = StockDefine::STOCK_API_TOKEN;





        while (true) {
            $t = time();
            if ($t > strtotime(date('9:25'))) {
                echo '执行完毕';
                break;
            }
            $field = 'name,code';
            $gupiaoList = collection(Gupiao::field($field)->select())->toArray();

            foreach ($gupiaoList as $item) {
                $requestUrl = "https://stockapi.com.cn/v1/base/second?token={$token}&code={$item['code']}&all=1";
                $ret = get_curl_data($requestUrl);
                $result = $ret[1];
                $result = json_decode($result, true);


                sleep(1);
            }
        }
    }

    /*protected function execute(Input $input, Output $output){
        $token = StockDefine::STOCK_API_TOKEN;

        while (true) {
            $t = time();
            if ($t > strtotime(date('9:25'))) {
                echo '执行完毕';
                break;
            }
            $field = 'name,code';
            $gupiaoList = collection(Gupiao::field($field)->select())->toArray();

            foreach ($gupiaoList as $item) {
                $requestUrl = "https://stockapi.com.cn/v1/base/second?token={$token}&code={$item['code']}&all=1";
                $ret = get_curl_data($requestUrl);
                $result = $ret[1];
                $result = json_decode($result, true);


                sleep(1);
            }
        }
    }*/
}
